


import ipyturtle3 as turtle
from ipyturtle3 import hold_canvas
myCanvas=turtle.Canvas(width=1000,height=500)
display(myCanvas)
myTS=turtle.TurtleScreen(myCanvas)


myTS=turtle.TurtleScreen(myCanvas)
myTS.clear()
myTS.bgcolor("lightgreen")
bob=turtle.Turtle(myTS)
bob.shape("turtle")



myTS.delay(0)
n=10
colors = ['red', 'purple', 'blue', 'green', 'orange', 'yellow']
t = turtle.Turtle(myTS)
t.shape("turtle")
for _ in range(25):
    with(hold_canvas(myCanvas)):
        t.pencolor(colors[_%6])
    for _ in range(4):
        t.forward(n)
        t.left(90)
    t.left(15)
    n+=5


a = 1
for _ in range(2):
  for _ in range(360):
      bob.forward(a)
      bob.left(1)
  a+=0.5


import ipyturtle3 as turtle
import random
import time
from ipyturtle3 import hold_canvas
random.seed(time.time())
myCanvas = turtle.Canvas(width=500, height=250)
display(myCanvas)
myTS = turtle.TurtleScreen(myCanvas)
myTS.clear()
myTS.bgcolor("lightgreen")

pen = turtle.Turtle(myTS)
pen.hideturtle()
pen.penup()
pen.goto(-100, 100)
pen.pendown()
pen.goto(-100, -100)
pen.penup()
pen.goto(100, 100)
pen.pendown()
pen.goto(100, -100)

bob = turtle.Turtle(myTS)
hare = turtle.Turtle(myTS)
bob.shape("turtle")
hare.shape("circle")  #好像没有兔子模型
bob.penup()
hare.penup()
bob.goto(-100, 50)
hare.goto(-100, -50)
bob.pendown()
hare.pendown()

myTS.delay(50)

bob_0, hare_0 = 0, 0
b_speed, h_speed = 0.3, 5.0  #乌龟0.3米/秒，兔子5米/秒
lazy_time = 0

print("比赛开始! 总距离200米")
for x in range(1000):
    if bob_0 >= 200 or hare_0 >= 200:
        break
    bob.forward(b_speed)
    bob_0 += 0.3
    if lazy_time > 0:
        lazy_time -= 1
    else:
        hare.forward(h_speed)
        hare_0 += 5.0
        if hare.xcor() - bob.xcor() >= 100 and random.random() < 0.8:
            lazy_time = random.randint(600, 700)
            print(f"兔子开始打盹了，加油啊龟龟，现在就是你反超的时候了")
            
if bob_0 > hare_0:
    result = "是乌龟赢了!"
elif bob_0 < hare_0:
    result = "是兔子赢了!"
else: result = "平局!"
print(f"比赛结束! {result}")



